package com.zhh.dao;

import com.zhh.pojo.TbFacilityLease;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.persistence.OrderBy;
import java.util.List;

public interface FacilityLeaseDao extends JpaRepository<TbFacilityLease,String> {

    @OrderBy("create_time asc")
    TbFacilityLease findTopByFacilityIdAndState(@Param("facilityId") int id,@Param("state") int state);

    @Modifying
    @Query("update TbFacilityLease l set l.state = :state,l.returnTime = current_time where l.id = :id")
    int updateStateById(@Param("id") String id, @Param("state") int state);


    List<TbFacilityLease> findByOrderIdAndStateGreaterThanEqual(@Param("orderId") String orderId,@Param("state") int state);

    List<TbFacilityLease> findByOrderIdAndState(@Param("orderId") String orderId,@Param("state") int state);
}
